package cn.fch.gotrip.controller;

import cn.fch.gotrip.api.BeanResponse;
import cn.fch.gotrip.entity.HotelOrder;
import cn.fch.gotrip.service.HotelOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: gotrip
 * @description:
 * @CreatedBy: fch
 * @create: 2023-01-26 09:55
 **/
@RestController
@RequestMapping("hotel-order")
public class HotelOrderController {

    @Autowired
    private HotelOrderService hotelOrderService;

    @PostMapping
    public BeanResponse creatOrder(@RequestBody HotelOrder hotelOrder) {
        if (hotelOrderService.creatHotelOrder(hotelOrder)) {
            return BeanResponse.ok(hotelOrder);
        } else {
            return BeanResponse.badRequest("创建失败");
        }
    }

    @DeleteMapping("{id}")
    public BeanResponse deleteOrder(@PathVariable String id) {
        if (hotelOrderService.deleteOrder(id)) {
            return BeanResponse.ok(hotelOrderService.deleteOrder(id), "删除成功");
        } else {
            return BeanResponse.badRequest("删除失败");
        }
    }

    @GetMapping("{id}")
    public BeanResponse queryOrderById(@PathVariable String id) {
        return BeanResponse.ok(hotelOrderService.queryOrderById(id));
    }

    @GetMapping("search/{id}/page/{pageNum}")
    public BeanResponse searchOrderById(@PathVariable String id,
                                        @PathVariable Integer pageNum,
                                        @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return BeanResponse.ok(hotelOrderService.searchOrderById(id, pageNum, pageSize));
    }

    @GetMapping("type/{type}/start/{start}/end/{end}/page/{pageNum}")
    public BeanResponse queryByCreatAndType(@PathVariable Integer type,
                                            @PathVariable Long start,
                                            @PathVariable Long end,
                                            @PathVariable Integer pageNum,
                                            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return BeanResponse.ok(hotelOrderService.queryByCreatAndType(type, pageNum, pageSize, start, end));
    }
}
